package ManagerSystem;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;

import tjut.db.DBDriverFactory;
import tjut.entity.FRIENDEntity;
import tjut.entity.MANAGERSYSEntity;
import tjut.entity.MANAGERSYSEntity2;


/**
 * 查询信息
 * @author ChrisL
 *
 */
public class SearchInfo {

	public void SearchStu(){
		String strSQL = "select * from MANAGERSYS WHERE ISDELETE=1";
		List lst = (List) DBDriverFactory.getDBDriverInstance().query(strSQL, new BeanListHandler(MANAGERSYSEntity.class));
		Collections.reverse(lst);
		Print.printList(lst);
	}
	@Test
	public void SearchStu2(){
		System.out.println("***************查询方式***************");
		System.out.println("*          1.查询所有学生信息                                *");
		System.out.println("*          2.查询指定编号学生信息                        *");
		System.out.println("*          3.姓名模糊查询学生信息                        *");
		System.out.println("*          4.地址模糊查询学生信息                        *");
		System.out.println("*          5.年龄段查询学生信息                            *");
		System.out.println("*          0.   退出                                               *");
		Scanner input = new Scanner(System.in);
		System.out.println("请输入序号：");
		int choose=input.nextInt();
		switch(choose){
		case 1:
			String strSQL = "select * from MANAGERSYS WHERE ISDELETE=1 ORDER BY STU_ID";
		    List lst = (List) DBDriverFactory.getDBDriverInstance().query(strSQL, new BeanListHandler(MANAGERSYSEntity2.class));
		    Collections.reverse(lst);
		    printList(lst);
		    break;
		case 2:
			System.out.println("请输入想单独查找的学生ID：");
			String Stuid=input.next();
			String strSQL1 = "select * from MANAGERSYS WHERE ISDELETE=1 AND STU_ID='"+Stuid+ "'";
			List lst1 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL1, new BeanListHandler(MANAGERSYSEntity2.class));
			printList(lst1);
			break;
		case 3:
			System.out.println("请输入姓名模糊查找字段：");
			String Stuname=input.next();
			String strSQL2 = "select * from MANAGERSYS WHERE STU_NAME LIKE '%"+Stuname+"%'";
			List lst2 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL2,new BeanListHandler(MANAGERSYSEntity2.class));
			printList(lst2);
			break;
		case 4:
			System.out.println("请输入地址模糊查找字段：");
			String Stuadd=input.next();
			String strSQL3 = "select * from MANAGERSYS WHERE STU_ADDRESS LIKE '%"+Stuadd+"%'";
			List lst3 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL3,new BeanListHandler(MANAGERSYSEntity2.class));
			printList(lst3);
			break;
		case 5:
			System.out.println("请输入年龄段a-b：");
			System.out.print("输入a：");
			String a=input.next();
			System.out.print("输入b：");
			String b=input.next();
			String strSQL4 = "select * from MANAGERSYS WHERE STU_AGE BETWEEN "+a+" AND "+ b+"";
			List lst4 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL4,new BeanListHandler(MANAGERSYSEntity2.class));
			printList(lst4);
			break;
		case 0:
			System.out.println("已退出");
			Teacher t=new Teacher();
			t.Function();
		}
		
	}
	
	
	
	public void SearchMe(String UserStu){
		String strSQL = "select * from MANAGERSYS WHERE STU_ID='"+UserStu+"'";
		List lst = (List) DBDriverFactory.getDBDriverInstance().query(strSQL, new BeanListHandler(MANAGERSYSEntity.class));
		printList(lst);
	}
	
	public void SearchOther(){
		Scanner input=new Scanner(System.in);
		System.out.println("请输入你想查询的同学姓名:");
		String Stuname=input.next();
		String strSQL2 = "select STU_ID ,STU_NAME,STU_SEX,STU_AGE,STU_PHONE,STU_ADDRESS from MANAGERSYS WHERE STU_NAME='"+Stuname+"'";
		List lst2 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL2, new BeanListHandler(MANAGERSYSEntity.class));
		printList(lst2);
	}
	
	public void SearchFriend(String UserStu){
		String strSQL4 = "select STU_ID ,FRD_NAME,FRD_ID,REMARK from FRIEND  WHERE STU_ID='"+UserStu+"'";
		List lst4 = (List) DBDriverFactory.getDBDriverInstance().query(strSQL4, new BeanListHandler(FRIENDEntity.class));
		printList(lst4);
	}
	
	public static void printList(List lst) {
		System.out.println("***********************");
		for (int i = 0; i < lst.size(); i++) {
			System.out.println(lst.get(i).toString());
		}

	}
}
